﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using KTXD.Entities;
using KTXD.Data;

namespace UserKTXD.DCTEDU_.CauHinhWeb
{
    public partial class QLCauHinh : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Bind_Data();
            }
        }

        private void Bind_Data()
        {
            TList<CauHinh> TList_SanPham = DataRepository.CauHinhProvider.GetAll();
            gridCatalog.DataSource = TList_SanPham;
            gridCatalog.DataBind();
        }

        protected void gridCatalog_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.backgroundColor='WhiteSmoke';";
                e.Row.Attributes["onmouseout"] = "this.style.backgroundColor='White';";
            }
        }

        string connectionString = ConfigurationManager.ConnectionStrings["netTiersConnectionString"].ConnectionString;
        protected void cmdTaoMoi_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < gridCatalog.Rows.Count; i++)
            {
                TextBox txtTenCauHinh = (TextBox)gridCatalog.Rows[i].Cells[0].FindControl("txtTenCauHinh");
                TextBox txtHienThi = (TextBox)gridCatalog.Rows[i].Cells[0].FindControl("txtHienThi");
                TextBox txtShow = (TextBox)gridCatalog.Rows[i].Cells[0].FindControl("txtShow");

                HiddenField H_IdCatalog = (HiddenField)gridCatalog.Rows[i].Cells[0].FindControl("H_IdCatalog");
                SqlConnection conn = new SqlConnection(connectionString);
                conn.Open();
                string query = "UPDATE CauHinh SET TenCTCauHinh = N'" + txtTenCauHinh.Text + "', NoiDung=N'" + txtHienThi.Text + "' where Id = '" + H_IdCatalog.Value + "'";
                SqlCommand sqlCommand = new SqlCommand();
                sqlCommand.Connection = conn;
                sqlCommand.CommandText = query;
                sqlCommand.ExecuteNonQuery();
                conn.Close();
            }
            Bind_Data();
        }
    }
}